<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="static org.apache.struts2.ServletActionContext.getServletContext" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ld.xuanKe.entity.*" %>
<%@ page import="com.ld.xuanKe.service.XsTeachingClassService" %>
<%@ page import="com.ld.xuanKe.service.impl.XsTeachingClassServiceImpl" %>
<%@ page import="com.ld.xuanKe.service.UserService" %>
<%@ page import="com.ld.xuanKe.service.impl.UserServiceImpl" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-10
  Time: 16:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>教学班学生</title>
    <link rel="stylesheet" type="text/css" href="/common.css" />
</head>
<body>

<%
    ApplicationContext applicationContext = (ApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    XsTeachingClassService xsTeachingClassService = (XsTeachingClassServiceImpl) applicationContext.getBean(XsTeachingClassService.class);
    UserService userService = (UserServiceImpl) applicationContext.getBean(UserService.class);
    String teachingClassId0 = request.getParameter("teachingClassId");
    User user = (User)session.getAttribute("user");
    List<XsTeachingClassDisplay> teachings = new ArrayList<>();
    if(teachingClassId0 == null){
        teachings = xsTeachingClassService.displayList();
    }else {
        try {
            Integer teachingClassId = Integer.parseInt(teachingClassId0);
            teachings = xsTeachingClassService.displayListByClassId(teachingClassId);
        } catch (NumberFormatException e) {
            teachings = xsTeachingClassService.displayList();
        }
    }
    String homePath;
    if (user.getStatus() == 0) {
        homePath = "user";
    } else {
        homePath = "admin";
    }

%>
<a href="/home/<%=homePath%>/index.jsp"
   style="display: inline-block;height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:#DDD;text-decoration: none;">返回个人管理页面</a>
<form id='like' action='/home/admin/teachingClass.jsp' method='get'><input name='teachingClassId'>&nbsp&nbsp<input type='submit' value='按教学班id查询'>
</form>
<form id='like' action='/xsTeachingClass/downLoad' method='get'><input name='teachingclassId'>&nbsp&nbsp<input type='submit' value='按教学班id导出excel'>
</form>
<c:if test="<%=teachings.isEmpty()%>">
    <h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!</h1>
</c:if>
<c:if test="<%=!teachings.isEmpty()%>">
    <table id='all-request' class='container'>
        <thead>
        <tr>
            <th>教学班id</th>
            <th>学生id</th>
            <th>学号</th>
            <th>姓名</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="<%=teachings%>" var="teaching">
            <tr>
                <td>${teaching.getTeachingClassId()}</td>
                <td>${teaching.getUserId()}</td>
                <td>${teaching.getAccount()}</td>
                <td>${teaching.getUsername()}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</c:if>
</body>
<script>
</script>
</html>
